#include"gua.h"
#include<malloc.h>
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
int
main()
{
	printf("Welcome to Iching!\n");
	gua_t *gua = (gua_t *)malloc(sizeof(gua_t));
	char *command = (char*)malloc(sizeof(char)*10);
	char *guaxiang = (char*)malloc(sizeof(char)*20);
	while(1){
		printf(">>");
		scanf("%s",command);
		if(strcmp(command,"help")==0){
			printf("b\t查询本卦\nh\t查询互卦\nz\t查询之卦\ng\t重新手动起卦\nq\t退出\n");
		}else if(strcmp(command,"g")==0){
			printf("请输入卦象:");
			scanf("%s",guaxiang);
			init_gua(gua,guaxiang);
		}else if(strcmp(command,"b")==0){
			guaxiang=strncpy(guaxiang,gua->bengua,6);
			guaxiang[6]='\0';
			readguaci(guaxiang);
		}else if(strcmp(command,"h")==0){
			guaxiang=strncpy(guaxiang,gua->hugua,6);
			guaxiang[6]='\0';
			readguaci(guaxiang);
		}else if(strcmp(command,"z")==0){
			guaxiang=strncpy(guaxiang,gua->zhigua,6);
			guaxiang[6]='\0';
			readguaci(guaxiang);
		}else if(strcmp(command,"q")==0){
			break;
		}else if(strcmp(command,"y")==0){
			int i=0;
			for(;i<6;i++){
				if(gua->yaoflag[i]=='1'){
					printf("第%d爻变动\n",i+1);
				}
			}
		}else{
			printf("b\t查询本卦\nh\t查询互卦\nz\t查询之卦\nq\t重新手动起卦\n");
		}
	}
	exit(0);
}
